[% PROCESS settings/header.html %]

	[% YESNOBOX = [['',''], ['PLUGIN_UPNPBRIDGE_YES','1'], ['PLUGIN_UPNPBRIDGE_NO','0']] %]
		
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_AUTORUN" desc="PLUGIN_UPNPBRIDGE_AUTORUN_DESC" %]
		<input name="autorun" type="checkbox" [% IF autorun %] checked [% END %]> [% "PLUGIN_UPNPBRIDGE_RUNNING_$running" | string %] [% IF binary %] ([% binary %]) [% END %]
		[%IF running %] &nbsp<input name="restart" type="submit" value=[% "PLUGIN_UPNPBRIDGE_RESTART" | string %]> [% END %]
		&nbsp&nbsp<b><a href="[% webroot %]upnpbridge-guide.htm" target="user guide">[% "PLUGIN_UPNPBRIDGE_USERGUIDELINK" | string %]</a></b>
		[%IF running %] <b><font color="red">&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_WARNING" | string %]</font></b> [% END %]
	[% END %]
	
	[% IF binaries.size > 1 %]
		[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_BINARIES" desc="PLUGIN_UPNPBRIDGE_BINARIES_DESC" %]
			<select class="stdedit" name="bin" id="bin">
			[% FOREACH entry IN binaries %]
				<option [% IF entry == bin %]selected[% found = 1 %][% END %] value="[% entry %]">[% entry %]</option>
			[% END %]
			[% IF not found %]
				<option selected value="">[% "PLUGIN_UPNPBRIDGE_BINARIES" | string %]</option>
			[% END %]
			</select>
		[% END %]
	[% END %]
		
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_OPTIONS" desc="PLUGIN_UPNPBRIDGE_OPTIONS_DESC" %]
		<input type="text" class="stdedit" name="opts" id="opts" value="[% opts %]" size="100">
	[% END %]
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_DEBUG" desc="PLUGIN_UPNPBRIDGE_DEBUG_DESC" %]
		<select class="stdedit" name="debugs" id="debugs">
		[% FOREACH entry IN [ '', 'all', 'output', 'stream', 'slimproto', 'slimmain', 'decode', 'upnp', 'util', 'main'] %]
			<option [% IF entry == debugs %]selected[% END %] value="[% entry %]">[% "PLUGIN_UPNPBRIDGE_$entry" | string %]</option>
		[% END %]
		</select>
	[% END %]
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_LOGGING" desc="PLUGIN_UPNPBRIDGE_LOGGING_DESC" %]
		<input name="logging" type="checkbox" [% IF logging %] checked [% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_LOGENABLE" | string %]
		&nbsp<a href="[% webroot %]upnpbridge-log.log" target="log">[% "PLUGIN_UPNPBRIDGE_LOGLINK" | string %]</a>
		&nbsp[% "PLUGIN_UPNPBRIDGE_LOGSIZE" | string %]&nbsp<input [% IF !xmlparams %] disabled [% END %] type="text" class="stdedit" name="log_limit" id="log_limit" value="[% log_limit %]" size="2"> 
		&nbsp<input name="eraselog" type="checkbox" [% IF eraselog %] checked [% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_ERASELOG" | string %]
		&nbsp<input name="cleanlog" type="submit" value=[% "PLUGIN_UPNPBRIDGE_CLEANLOG" | string %]> 
	[% END %]
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_CONFIG" desc="PLUGIN_UPNPBRIDGE_CONFIG_DESC" %]
		[% configpath %]
		<input type="text" class="stdedit" name="configfile" id="configfile" value="[% configfile %]" size="20">
		<a href="[% webroot %]upnpbridge-config.xml" target="config">[% "PLUGIN_UPNPBRIDGE_CONFLINK" | string %]</a>
		&nbsp&nbsp<input name="autosave" type="checkbox" [% IF autosave %] checked [% END %]>[% "PLUGIN_UPNPBRIDGE_AUTOSAVECONFIG" | string %]
		[% IF binary %]
			&nbsp<input name="genconfig" type="submit" onclick="alert('generating configuration will take ~30 seconds')" value=[% "PLUGIN_UPNPBRIDGE_GENCONFIG" | string %]>
		[% END %]	
		&nbsp<input name="delconfig" type="submit" value=[% "PLUGIN_UPNPBRIDGE_DELCONFIG" | string %]>
	[% END %]
	
	<script type="text/javascript">
	function lmssocket(item) {
		var params = document.getElementById('xmlparams') != null;
		document.getElementById('binding').disabled = item.checked || !params;
		document.getElementById('baseport_span').style.display = (item.checked && params) ? 'inline' : 'none';
	}
	</script>	
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_BINDING" desc="PLUGIN_UPNPBRIDGE_BINDING_DESC" %]
		<input type="text" class="stdedit" name="binding" id="binding" value="[% binding %]" size="16" [% IF useLMSsocket || !xmlparams %] disabled [% END %]>
		&nbsp<input name="useLMSsocket" type="checkbox" onchange="lmssocket(this)" [% IF useLMSsocket %] checked [% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_USELMSBINDING" | string %]
		<span id="baseport_span" [% IF !useLMSsocket || !xmlparams %] hidden [% END %]>
			[% "PLUGIN_UPNPBRIDGE_BASEPORT" | string %]
			&nbsp<input type="text" class="stdedit" name="baseport" id="baseport" value="[% baseport %]" size="3">
		</span>		
	[% END %]
	
	[% IF !xmlparams %]
		[% WRAPPER settingSection %]
			<b><font color=red>[% "PLUGIN_UPNPBRIDGE_NOCONFIG" | string %]</font></b>
		[% END %]	
	[% ELSE %]
	
	<input hidden type="text" class="stdedit" name="xmlparams" id="xmlparams" value="1" size="5">
	<input hidden type="text" class="stdedit" name="prevseldevice" id="prevseldevice" value="[% prevseldevice %]" size="5">

	<hr>

	[% WRAPPER settingSection %]
		<select class="stdedit" name="seldevice" id="seldevice" onchange="form.submit()">
		[% FOREACH entry IN devices %]
			<option [% IF entry.udn == seldevice %]selected[% END %] value="[% entry.udn %]">[% entry.name %]</option>
		[% END %]
		</select>
		[% IF seldevice == '.common.' %]<b><font color=red>&nbsp&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_COMMONPARAMINFO" | string %]</font></b>
		[% ELSE %]<b><font color=red>&nbsp&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_PARAMINFO" | string %]</font></b>[% END %]
	[% END %]
	
	[% IF seldevice != '.common.' %]
		[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_USEPROFILE" desc="PLUGIN_UPNPBRIDGE_USEPROFILE_DESC" %]
			[%IF devicesprofiles %]
				<select class="stdedit" name="selprofile" id="selprofile">
				[% FOREACH entry IN devicesprofiles %]
					<option value="[% entry %]">[% entry %]</option>
				[% END %]
				</select>
				&nbsp<input name="applyprofile" type="checkbox">[% "PLUGIN_UPNPBRIDGE_APPLYPROFILE" | string %] 
			[% END %]	
			&nbsp&nbsp<input name="updateprofiles" type="submit" onclick="alert('fetching will take a few seconds')" value=[% "PLUGIN_UPNPBRIDGE_UPDATEPROFILES" | string %]> 
			&nbsp[% "PLUGIN_UPNPBRIDGE_UPDATEPROFILESFROM" | string %]&nbsp&nbsp<input type="text" class="stdedit" name="updatefrom" id="updatefrom" value="[% updatefrom %]" size="30">
		[% END %]
		
		[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_PLAYERINFO" desc="PLUGIN_UPNPBRIDGE_PLAYERINFO_DESC" %]
			<th>[% "PLUGIN_UPNPBRIDGE_PLAYERNAME" | string %]</th>
			<td><input type="text" class="stdedit" name="name" id="name" value="[% name %]" size="25"></td>
			<th>[% "PLUGIN_UPNPBRIDGE_PLAYERMAC" | string %]</th>
			<td><input type="text" class="stdedit" name="mac" id="mac" value="[% mac %]" size="20"></td>
			<td><input name="deldevice" type="checkbox"></td>
			<th>[% "PLUGIN_UPNPBRIDGE_DELETEPLAYER" | string %]</th>
		[% END %]
	[% END %]		
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_STREAMOPTIONS" desc="PLUGIN_UPNPBRIDGE_STREAMOPTIONS_DESC" %]
		[% "PLUGIN_UPNPBRIDGE_HTTPMODE" | string %]
		<select class="stdedit" id="stream_length" name="stream_length">
		[% FOREACH entry IN [ ['',''], ['PLUGIN_UPNPBRIDGE_HTTPMODECHUNKED','-3'], ['PLUGIN_UPNPBRIDGE_HTTPMODEIFKNOWN', '-2'], ['PLUGIN_UPNPBRIDGE_HTTPMODENOLENGTH','-1'], ['PLUGIN_UPNPBRIDGE_HTTPMODEFIXED', '2048000000'] ] %]
			<option label="[% entry.0 | string %]" [% IF entry.1 == stream_length %]selected[% END %] value="[% entry.1 %]">
		[% END %]
		</select>
		[% "PLUGIN_UPNPBRIDGE_ACCEPTNEXTURI" | string %]
		&nbsp<select class="stdedit" name="accept_nexturi" id="accept_nexturi">
		[% FOREACH entry IN [ ['', ''], ['PLUGIN_UPNPBRIDGE_YES','1'], ['PLUGIN_UPNPBRIDGE_NO', '0'], ['PLUGIN_UPNPBRIDGE_NEXTFORCE','-1'] ] %]
			<option [% IF entry.1 == accept_nexturi %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
		[% "PLUGIN_UPNPBRIDGE_SEEKAFTERPAUSE" | string %]&nbsp
		<select class="stdedit" name="seek_after_pause" id="seek_after_pause">
		[% FOREACH entry IN YESNOBOX %] 
			<option [% IF entry.1 == seek_after_pause %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
		&nbsp[% "PLUGIN_UPNPBRIDGE_NEXTDELAY1" | string %]
		<input type="text" class="stdedit" name="next_delay" id="next_delay" value="[% next_delay %]" size="2">
		[% "PLUGIN_UPNPBRIDGE_NEXTDELAY2" | string %]
	[% END %]
	
	<script type="text/javascript">
	function showadvanced(status, options) {
		var options = document.getElementById(options);
		options.style.display = (status.checked) ? 'inline' : 'none';
	}
	</script>
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_UPNPAUDIOCAPS" desc="PLUGIN_UPNPBRIDGE_UPNPAUDIOCAPS_DESC" %]
		[% "PLUGIN_UPNPBRIDGE_CODECS" | string %]
		<input type="text" class="stdedit" name="codecs" id="codecs" value="[% codecs %]" size="20">&nbsp
		[% "PLUGIN_UPNPBRIDGE_SAMPLERATE" | string %]
		<select class="stdedit" name="sample_rate" id="sample_rate">
		[% FOREACH entry IN [ '', '44100', '48000', '88200', '96000', '176400', '192000' ] %]
			<option [% IF entry == sample_rate %]selected[% END %] value="[% entry %]">[% entry %]</option>
		[% END %]
		</select>&nbsp&nbsp
		<input name="advanced_upnpaudio_flag" type="checkbox" onchange="showadvanced(this,'advanced_upnpaudio')" [% IF advanced_upnpaudio_flag %]checked [% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_ADVANCED" | string %]
		<span id="advanced_upnpaudio" [% IF !advanced_upnpaudio_flag %]hidden[% END %]><br><br>
			[% "PLUGIN_UPNPBRIDGE_RAWAUDIOFORMAT" | string %]&nbsp
			<input type="text" class="stdedit" name="raw_audio_format" id="raw_audio_format" value="[% raw_audio_format %]" size="8">&nbsp&nbsp
			[% "PLUGIN_UPNPBRIDGE_FORCEDMIMETYPES" | string %]&nbsp
			<input type="text" class="stdedit" name="forced_mimetypes" id="forced_mimetypes" value="[% forced_mimetypes %]" size="20">
		</span>
	[% END %]
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_ENCODEPARAMS" desc="PLUGIN_UPNPBRIDGE_ENCODEPARAMS_DESC" %]
		<script type="text/javascript">
		function modechange(input) {
			var mode = input.options[input.selectedIndex].value;
			var process = document.getElementsByClassName('encode_process');
			var	thru = document.getElementById('encode_thru');
			var	flac = document.getElementById('encode_flac');
			var	mp3 = document.getElementById('encode_mp3');
						
			thru.style.display = flac.style.display = mp3.style.display = 'none';
			for (var i = 0; i < process.length; i++) {
				process[i].style.display = 'inline';
			}
												
			if (!mode || mode === 'thru') {
				thru.style.display = 'inline';
				for (var i = 0; i < process.length; i++) {
					process[i].style.display = 'none';
				}
			} else if (mode === 'flc') {
				flac.style.display = 'inline';
			} else if (mode === 'mp3') {
				mp3.style.display = 'inline';
			}	
		}
		</script>
		
		[% "PLUGIN_UPNPBRIDGE_ENCODEMODE" | string %]
		<select class="stdedit" name="encode_mode" id="encode_mode" onchange="modechange(this)">
		[% FOREACH entry IN [ ['',''], ['none','thru'], ['pcm','pcm'], ['flac', 'flc'], ['mp3', 'mp3'] ] %]
			<option [% IF entry.1 == encode_mode %]selected[% END %] value="[% entry.1 %]">[% entry.0 %]</option>
		[% END %]
		</select>&nbsp
		<span class="encode_process" [% IF !encode_mode || encode_mode == 'thru' %]hidden[% END %]>
			<input name="encode_flow" type="checkbox" [% IF encode_flow %] checked [% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_ENCODEFLOW" | string %]&nbsp
		</span>
		[% "PLUGIN_UPNPBRIDGE_L24FORMAT" | string %]
		<select class="stdedit" name="L24_format" id="L24_format">
		[% FOREACH entry IN [ ['',''], ['PLUGIN_UPNPBRIDGE_L24PLAIN','0'], ['PLUGIN_UPNPBRIDGE_L24PACKED1','1'] ['PLUGIN_UPNPBRIDGE_L24ALWAYS16','2'] ['PLUGIN_UPNPBRIDGE_L24RAWONLY16', '3'] ] %]
			<option [% IF entry.1 == L24_format %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>&nbsp&nbsp
		<input name="advanced_encode_flag" type="checkbox" onchange="showadvanced(this,'advanced_encode')" [% IF advanced_encode_flag %]checked [% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_ADVANCED" | string %]
		<span id="advanced_encode" [% IF !advanced_encode_flag %]hidden[% END %]>
			<br><br>
			<span id="encode_thru" [% IF encode_mode && encode_mode != 'thru' %]hidden[% END %]>
				[% "PLUGIN_UPNPBRIDGE_FLACHEADER" | string %]&nbsp
				<select class="stdedit" name="flac_header" id="flac_header">
				[% FOREACH entry IN [ ['',''], ['none','0'], ['normal','1'], ['fixed size','2'] ] %]
					<option [% IF entry.1 == flac_header %]selected[% END %] value="[% entry.1 %]">[% entry.0 %]</option>
				[% END %]
				</select>&nbsp
			</span>
			<span class="encode_process" [% IF !encode_mode || encode_mode == 'thru' %]hidden[% END %]>
				<span id="encode_flac" [% IF encode_mode != 'flc' %]hidden[% END %]>
					[% "PLUGIN_UPNPBRIDGE_ENCODEFLACLEVEL" | string %]
					<select class="stdedit" name="encode_level" id="encode_level">
					[% FOREACH entry IN [ '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ] %]
						<option [% IF entry == encode_level %]selected[% END %] value="[% entry %]">[% entry %]</option>
					[% END %]
					</select>&nbsp
				</span>
				<span id="encode_mp3" [% IF encode_mode != 'mp3' %]hidden[% END %]>
					[% "PLUGIN_UPNPBRIDGE_ENCODEMP3BITRATE" | string %]
					<select class="stdedit" name="encode_bitrate" id="encode_bitrate">
					[% FOREACH entry IN [ '', '64', '96', '128', '144', '160', '192', '224', '256', '320' ] %]
						<option [% IF entry == encode_bitrate %]selected[% END %] value="[% entry %]">[% entry %]</option>
					[% END %]
					</select>&nbsp
				</span>
				<script type="text/javascript">
				function encoderate(rate) {
					var param = document.getElementById('encode_rate_span');
					param.style.display = rate.options[rate.selectedIndex].value ? 'inline' : 'none';
				}
				</script>
				[% "PLUGIN_UPNPBRIDGE_ENCODERATE" | string %]
				<select class="stdedit" name="encode_rate" id="encode_rate" onchange="encoderate(this)">
				[% FOREACH entry IN [ ['source',''], ['44100','44100'], ['48000','48000'], ['88200','88200'], ['96000','96000'], ['176400','176400'], ['192000','192000'] ] %]
					<option [% IF entry.1 == encode_rate %]selected[% END %] value="[% entry.1 %]">[% entry.0 %]</option>
				[% END %]
				</select>
				<span id="encode_rate_span"  [% IF !encode_rate %]hidden[% END %]>
					<input name="encode_rate_flag" type="checkbox"[% IF encode_rate_flag %]checked[% END %]>&nbsp[% "PLUGIN_UPNPBRIDGE_ENCODERATEFLAG" | string %]
				</span>&nbsp
				[% "PLUGIN_UPNPBRIDGE_ENCODESIZE" | string %]
				<select class="stdedit" name="encode_size" id="encode_size">
				[% FOREACH entry IN [ ['source',''], ['8','8'], ['16','16'], ['24','24'], ['32','32'] ] %]
					<option [% IF entry.1 == encode_size %]selected[% END %] value="[% entry.1 %]">[% entry.0 %]</option>
				[% END %]
				</select>&nbsp
			</span>	
		</span>	
	[% END %]
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_UPNPMGMT" desc="PLUGIN_UPNPBRIDGE_UPNPMGMT_DESC" %]
		[% "PLUGIN_UPNPBRIDGE_SERVER" | string %]&nbsp<input type="text" class="stdedit" name="server" id="server" value="[% server %]" size="10">
		&nbsp[% "PLUGIN_UPNPBRIDGE_ENABLEDEFS" | string %]
		<select class="stdedit" name="enabled" id="enabled">
		[% FOREACH entry IN YESNOBOX %] 
			<option [% IF entry.1 == enabled %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
		&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_REMOVETIMEOUT" | string %]
		<input type="text" class="stdedit" name="remove_timeout" id="remove_timeout" value="[% remove_timeout %]" size="2">
	[% END %]
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_VOLUMEMGMT" desc="PLUGIN_UPNPBRIDGE_VOLUMEMGMT_DESC" %]
		[% "PLUGIN_UPNPBRIDGE_MAXVOLUME" | string %]&nbsp</th><input type="text" class="stdedit" name="max_volume" id="max_volume" value="[% max_volume %]" size="3">
		&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_VOLUMEONPLAY" | string %]&nbsp<select class="stdedit" name="volume_on_play" id="volume_on_play">
		[% FOREACH entry IN [ ['',''], ['PLUGIN_UPNPBRIDGE_VOLUMEWHENPLAYING','1'], ['PLUGIN_UPNPBRIDGE_VOLUMEIGNORE','-1'], ['PLUGIN_UPNPBRIDGE_VOLUMEFORWARD','0'] ] %]
			<option [% IF entry.1 == volume_on_play %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
		&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_VOLUMEFEEDBACK" | string %]&nbsp
		<select class="stdedit" name="volume_feedback" id="volume_feedback">
		[% FOREACH entry IN YESNOBOX %] 
			<option [% IF entry.1 == volume_feedback %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
	[% END %]
	
	[% WRAPPER setting title="PLUGIN_UPNPBRIDGE_SENDMETADATA" desc="PLUGIN_UPNPBRIDGE_SENDMETADATA_DESC" %]
		<select class="stdedit" name="send_metadata" id="send_metadata">
		[% FOREACH entry IN YESNOBOX %] 
			<option [% IF entry.1 == send_metadata %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
		&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_SEND_COVERART" | string %]&nbsp
		<select class="stdedit" name="send_coverart" id="send_coverart">
		[% FOREACH entry IN YESNOBOX %] 
			<option [% IF entry.1 == send_coverart %]selected[% END %] value="[% entry.1 %]">[% entry.0 | string %]</option>
		[% END %]
		</select>
		&nbsp&nbsp[% "PLUGIN_UPNPBRIDGE_SENDICY" | string %]&nbsp
		<select class="stdedit" name="send_icy" id="send_icy">
		[% FOREACH entry IN {
				''  => '',
				'0' => 'PLUGIN_UPNPBRIDGE_NO',
				'1' => 'PLUGIN_UPNPBRIDGE_YES',
				'2' => 'PLUGIN_UPNPBRIDGE_ICYTEXT',
				} %] 
			<option [% IF entry.key == send_icy %]selected[% END %] value="[% entry.key %]">[% entry.value | string %]</option>
		[% END %]
		</select>
	[% END %]
	
	<hr>
	<b>[% "PLUGIN_UPNPBRIDGE_PLAYERLIST" | string %]</b><br>
	<br><table>
	[% FOREACH entry IN devices %]
		[% IF entry.udn != '.common.' %]
			<tr><td><input name="enabled.[% entry.udn %]" type="checkbox" value="1" [% IF entry.enabled %] checked [% END %]></td>
			<th>[% entry.name %]<th>&nbsp[% entry.mac %]</th><th>&nbsp[% entry.udn %]</th><th>&nbsp[% entry.friendly_name %]</th></tr>
		[% END %]
	[% END %]
	</table>
	
	[% END %]
		
[% PROCESS settings/footer.html %]
